<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${title} + ' - 图书管理系统'"></title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
<nav th:replace="fragments/navbar :: navbar"></nav>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8 offset-md-2">
            <div class="card">
                <div class="card-header">
                    <h3 th:text="${title}"></h3>
                </div>
                <div class="card-body">
                    <div th:if="${error}" class="alert alert-danger mb-4">
                        <span th:text="${error}"></span>
                    </div>
                    <div th:if="${message}" class="alert alert-success mb-4">
                        <span th:text="${message}"></span>
                    </div>
                    <form th:action="@{${book.id != null ? '/books/update/' + book.id : '/books'}}" method="post">
                        <div class="form-group">
                            <label for="title">书名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="title" name="title"
                                   th:value="${book.title}" required>
                        </div>
                        <div class="form-group">
                            <label for="author">作者 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="author" name="author"
                                   th:value="${book.author}" required>
                        </div>
                        <div class="form-group">
                            <label for="isbn">ISBN</label>
                            <input type="text" class="form-control" id="isbn" name="isbn"
                                   th:value="${book.isbn}">
                        </div>
                        <div class="form-group">
                            <label for="publisher">出版社</label>
                            <input type="text" class="form-control" id="publisher" name="publisher"
                                   th:value="${book.publisher}">
                        </div>
                        <div class="form-group">
                            <label for="publicationYear">出版年份</label>
                            <input type="number" class="form-control" id="publicationYear" name="publicationYear"
                                   th:value="${book.publicationYear}">
                        </div>
                        <div class="form-group">
                            <label for="description">图书描述</label>
                            <textarea class="form-control" id="description" name="description" rows="3"
                                      th:text="${book.description}"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="stock">库存数量 <span class="text-danger">*</span></label>
                            <input type="number" class="form-control" id="stock" name="stock"
                                   th:value="${book.stock}" min="0" required>
                        </div>
                        <div class="text-right">
                            <a href="/books" class="btn btn-secondary mr-2">取消</a>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>